package com.graduation.springbootinit.controller;

import com.graduation.springbootinit.common.BaseResponse;
import com.graduation.springbootinit.common.ResultUtils;
import com.graduation.springbootinit.model.entity.ShopPart.ProductParams;
import com.graduation.springbootinit.service.ProductParamService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/product/param")
public class ProductParamController {

    @Resource
    private ProductParamService productParamService;

    @PostMapping("/save")
    public BaseResponse<Boolean> saveOrUpdateParams(@RequestBody ProductParams productParams) {
        productParamService.saveOrUpdateParams(productParams.getProductId(), productParams.getParams());
        return ResultUtils.success(true);
    }

    @PostMapping("/delete/product")
    public BaseResponse<Boolean> deleteByProductId(@RequestBody ProductParams productParams) {
        productParamService.deleteByProductId(productParams.getProductId());
        return ResultUtils.success(true);
    }

    @PostMapping("/get")
    public BaseResponse<ProductParams> getParams(@RequestBody ProductParams productParams) {
        ProductParams result = new ProductParams();
        result.setProductId(productParams.getProductId());
        result.setParams(productParamService.getParamsByProductId(productParams.getProductId()));
        return ResultUtils.success(result);
    }
} 